using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.Data;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{

    public partial class VVAFARBEN
    {
        public readonly static VVAFARBEN Instance = new VVAFARBEN();
        private string _VART; public string VART { get { return _VART; } set { _VART = value; OnPropertyChanged("VART", value); } }


        private VWAFARBEN _VWF;
        public VWAFARBEN VWF
        {
            get
            {
                if (_VWF == null) _VWF = new VWAFARBEN();
                return _VWF;
            }
        }
        private VVAKOLL _VAK;
        public VVAKOLL VAK
        {
            get
            {
                if (_VAK == null) _VAK = new VVAKOLL();
                return _VAK;
            }
        }
        private VVAART _VAA;
        public VVAART VAA
        {
            get
            {
                if (_VAA == null) _VAA = new VVAART();
                return _VAA;
            }
        }

        VLMFKART LM;
        private DataRow _dwVA = null;
        public DataRow dwVA
        {
            get { return _dwVA; }
            set
            {
                _dwVA = value;
                if (value != null)
                {
                    KOLL = value["VAAKOLL"].ToString();
                    ART = value["VAAART"].ToString();
                }
                else
                {
                    KOLL = "";
                    ART = "";
                }
                OnPropertyChanged("dwVA", value);
            }
        }
        private DataRow _dwVF = null;
        public DataRow dwVF
        {
            get { return _dwVF; }
            set
            {
                _dwVF = value;
                OnPropertyChanged("dwVF", value);
            }
        }
        private string _COLORS = "";
        public string COLORS
        {
            get { return _COLORS; }
            set
            {
                _COLORS = value;
                OnPropertyChanged("COLORS", value);
            }
        }
        private string _VAFBEZ = "";
        public string VAFBEZ
        {
            get { return _VAFBEZ; }
            set
            {
                _VAFBEZ = value;
                OnPropertyChanged("VAFBEZ", value);
            }
        }
        private string _EXFARBE = "";
        public string EXFARBE
        {
            get { return _EXFARBE; }
            set
            {
                _EXFARBE = value;
                OnPropertyChanged("EXFARBE", value);
            }
        }

        private bool _IsByCards = false;
        public bool IsByCards
        {
            get { return _IsByCards; }
            set
            {
                _IsByCards = value;
                OnPropertyChanged("IsByCards", value);
            }
        }

        private bool _IsMoreThanOne = false;
        public bool IsMoreThanOne
        {
            get { return _IsMoreThanOne; }
            set
            {
                _IsMoreThanOne = value;
                OnPropertyChanged("IsMoreThanOne", value);
            }
        }

        public override void SetUp()
        {
            base.SetUp();
        }

        public void VFLOAD()
        {
            dwData = TBMain.NewRow();
            dwData["VAFMANDANT"] = app.Mandant;
            dwData["VAFKOLL"] = KOLL.Trim();
            dwData["VAFART"] = ART.Trim();
            dwData["VAFFARBE"] = FARBE.Trim();
            dwData["VAFFFARBE"] = DES.Trim();
            SResult = QVAF05(dwData);
            MergeData(SResult, false);
        }
        public DataSet LOAD(Dictionary<string, object> pm)
        {
            dwData = TBMain.NewRow();
            dwData["VAFMANDANT"] = app.Mandant;
            dwData["VAFKOLL"] = (string)pm["VAFKOLL"];
            dwData["VAFART"] = (string)pm["VAFART"];
            dwData["VAFFARBE"] = (string)pm["VAFFARBE"];
            SResult = QVAF02(dwData);
            MergeData(SResult, false);
            return SResult;
        }
        public bool CHKVAF(Dictionary<string, object> pm)
        {
            bool IsVAFReady = false;
            KOLL = pm["KOLL"].ToString();
            ART = pm["ART"].ToString();
            ARTST = pm["ARTST"].ToString();
            FARBE = pm["FARBE"].ToString();
            dwData = TBMain.NewRow();
            dwData["VAFMANDANT"] = app.Mandant;
            dwData["VAFKOLL"] = KOLL.PadRight(5);
            dwData["VAFART"] = ART.PadRight(24);
            dwData["VAFFARBE"] = FARBE.PadRight(10);
            SResult = QVAF04(dwData);
            if (SResult.Tables[0].Rows.Count > 0)
                IsVAFReady = true;
            return IsVAFReady;

        }
        public bool CHKVA(Dictionary<string, object> pm)
        {
            bool IsVAReady = false;
            KOLL = pm["KOLL"].ToString();
            ART = pm["ART"].ToString();
            ARTST = pm["ARTST"].ToString();
            FARBE = pm["FARBE"].ToString();
            dwData = VAA.TBMain.NewRow();
            dwData["VAAMANDANT"] = app.Mandant;
            dwData["VAAKOLL"] = KOLL.PadRight(5);
            dwData["VAAART"] = ART.PadRight(24);
            SResult = VAA.QVA01(dwData);
            if (SResult.Tables[0].Rows.Count > 0)
                IsVAReady = true;
            return IsVAReady;

        }
        public bool CHKWF(Dictionary<string, object> pm)
        {
            bool IsWFReady = false;
            KOLL = pm["KOLL"].ToString();
            ART = pm["ART"].ToString();
            ARTST = pm["ARTST"].ToString();
            FARBE = pm["FARBE"].ToString();

            dwData = VWF.TBMain.NewRow();
            dwData["WAFMANDANT"] = app.Mandant;
            dwData["WAFART"] = ART.PadRight(20);
            dwData["WAFVAR"] = "  ";
            dwData["WAFZUART"] = "C";
            dwData["WAFZUSATZ"] = FARBE.PadRight(10);
            SResult = VWF.QWAF10(dwData);
            if (SResult.Tables[0].Rows.Count > 0)
                IsWFReady = true;

            return IsWFReady;

        }
        public bool CHKWS(Dictionary<string, object> pm)
        {
            bool IsWSReady = false;
            KOLL = pm["KOLL"].ToString();
            ART = pm["ART"].ToString();
            ARTST = pm["ARTST"].ToString();
            dwData = VAA.VWS.TBMain.NewRow();
            dwData["WAMANDANT"] = app.Mandant;
            dwData["WAART"] = ART.PadRight(20);
            dwData["WAVAR"] = "  ";
            SResult = VAA.VWS.QWS31(dwData);
            if (SResult.Tables[0].Rows.Count > 0)
                IsWSReady = true;
            return IsWSReady;

        }
        public void AUTOCHK(Dictionary<string, object> pm)
        {
            KOLL = pm["KOLL"].ToString();
            ART = pm["ART"].ToString();
            ARTST = pm["ARTST"].ToString();
            FARBE = pm["FARBE"].ToString();
            DES = pm["DES"].ToString();
            if (KOLL.Trim().Length == 0)
            {

                return;
            }
            if (ART.Trim().Length == 0)
            {

                return;
            }
            PM["KOLL"] = KOLL;
            PM["ARTST"] = ARTST;
            PM["ART"] = ART;
            PM["VAAPRGR"] = Helper.Left(KOLL, 3);
            PM["VAAARTGRP"] = Helper.Left(KOLL, 3);
            PM["EXART"] = Helper.Left(ART.PadRight(20), 20);
            PM["DES"] = DES;
            VAA.NEWVAART(PM);

            dwData = TBMain.NewRow();
            SetUpNewRow(ref dwData);
            dwData["VAFKOLL"] = KOLL.PadRight(5);
            dwData["VAFART"] = ART.PadRight(24);
            dwData["VAFFARBE"] = FARBE.PadRight(10);
            dwData["VAFFFARBE"] = FARBE.PadRight(10);
            dwData["VAFBEZ"] = DES.PadRight(20);
            SResult = QVAF06(dwData);
            if (SResult.Tables[0].Rows.Count > 0)
            {
                UpdateVAFARBEN(dwData, app.company, 0);
                return;
            }
            Insert(dwData);
        }
        public void Insert(DataRow _dwVF)
        {
            try
            {
                _dwVF["VAFMANDANT"] = app.Mandant;
                if (dwVA == null)
                {
                    dwData = VAA.TBMain.NewRow();
                    dwData["VAAMANDANT"] = app.Mandant;
                    dwData["VAAKOLL"] = _dwVF["VAFKOLL"];
                    dwData["VAAART"] = _dwVF["VAFART"];
                    SResult = VAA.QVA02(dwData);
                    if (SResult.Tables[0].Rows.Count > 0)
                        dwVA = SResult.Tables[0].Rows[0];
                }
                if (dwVA != null)
                {
                    _dwVF["VAFPART"] = dwVA["VAADART"];
                    _dwVF["VAFPLART"] = dwVA["VAADART"];
                    _dwVF["VAFPART"] = dwVA["VAADART"];
                    _dwVF["VAFPVAR"] = dwVA["VAADVAR"];
                }

                else
                {
                    _dwVF["VAFPART"] = _dwVF["VAFART"].ToString().Substring(0, 20);
                    _dwVF["VAFPLART"] = _dwVF["VAFART"].ToString().Substring(0, 20);
                    _dwVF["VAFPART"] = _dwVF["VAFART"].ToString().Substring(0, 20);
                    _dwVF["VAFPVAR"] = "  ";
                }

                InsertVAFARBEN(_dwVF, app.company);
                string key = _dwVF["VAFKOLL"].ToString() + _dwVF["VAFART"].ToString() + _dwVF["VAFFARBE"].ToString();
                SResult = QVAF02(_dwVF);
                MergeData(SResult, false, false);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public virtual void Copy(Dictionary<string, object> pm)
        {
            string koll = (string)pm["KOLL"];
            string tart = (string)pm["TART"];
            string sart = (string)pm["SART"];
            dwData = TBMain.NewRow();
            dwData["VAFMANDANT"] = app.Mandant;
            dwData["VAFKOLL"] = koll;
            dwData["VAFART"] = sart.PadRight(24);
            SResult = QVAF01X(dwData);
            foreach (DataRow dwSrc in SResult.Tables[0].Rows)
            {
                dwData = TBMain.NewRow();
                dwData.ItemArray = dwSrc.ItemArray;
                dwData["VAFART"] = tart.PadRight(24);
                dwData["VAFPART"] = tart.PadRight(20);
                dwData["VAFPLART"] = tart.PadRight(20);
                dwData["VAFPART"] = tart.PadRight(20); 
                DVF01(dwData);
                InsertVAFARBEN(dwData);
            }
        }
    }
    //VAFDESS,VAFCOLORIT,VAFBESCHICH,VAFPGROE
    public partial class VVAFARBEN
    {
        public string VAFFARBE { get { if (dwMaster == null) return ""; return dwMaster["VAFFARBE"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFFARBE"] = value; OnPropertyChanged("VAFFARBE", value); } } //lENGth 10
        public string VAFKOLL { get { if (dwMaster == null) return ""; return dwMaster["VAFKOLL"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFKOLL"] = value; OnPropertyChanged("VAFKOLL", value); } } //lENGth 5
        public string VAFFFARBE { get { if (dwMaster == null) return ""; return dwMaster["VAFFFARBE"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFFFARBE"] = value; OnPropertyChanged("VAFFFARBE", value); } } //lENGth 10
        public string VAFDESS { get { if (dwMaster == null) return ""; return dwMaster["VAFDESS"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFDESS"] = value; OnPropertyChanged("VAFDESS", value); } } //lENGth 10
        public string VAFCOLORIT { get { if (dwMaster == null) return ""; return dwMaster["VAFCOLORIT"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFCOLORIT"] = value; OnPropertyChanged("VAFCOLORIT", value); } } //lENGth 10
        public string VAFBESCHICH { get { if (dwMaster == null) return ""; return dwMaster["VAFBESCHICH"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFBESCHICH"] = value; OnPropertyChanged("VAFBESCHICH", value); } } //lENGth 10
        public string VAFPGROE { get { if (dwMaster == null) return ""; return dwMaster["VAFPGROE"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFPGROE"] = value; OnPropertyChanged("VAFPGROE", value); } } //lENGth 7
        public string VAFPART { get { if (dwMaster == null) return ""; return dwMaster["VAFPART"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFPART"] = value; OnPropertyChanged("VAFPART", value); } } //lENGth 20
        public string VAFPVAR { get { if (dwMaster == null) return ""; return dwMaster["VAFPVAR"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFPVAR"] = value; OnPropertyChanged("VAFPVAR", value); } } //lENGth 2

        public string VAFART { get { if (dwMaster == null) return ""; return dwMaster["VAFART"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFART"] = value; OnPropertyChanged("VAFART", value); } } //lENGth 24
        public double VAFAENDDAT { get { if (dwMaster == null) return 0.0; return Convert.ToDouble(dwMaster["VAFAENDDAT"].ToString()); } set { if (dwMaster == null) return; dwMaster["VAFAENDDAT"] = value; OnPropertyChanged("VAFAENDDAT", value); } } //lENGth 0
        public double VAFNEUDAT { get { if (dwMaster == null) return 0.0; return Convert.ToDouble(dwMaster["VAFNEUDAT"].ToString()); } set { if (dwMaster == null) return; dwMaster["VAFNEUDAT"] = value; OnPropertyChanged("VAFNEUDAT", value); } } //lENGth 0
        public string VAFFARBGRP { get { if (dwMaster == null) return ""; return dwMaster["VAFFARBGRP"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFFARBGRP"] = value; OnPropertyChanged("VAFFARBGRP", value); } } //lENGth 1

        #region======ColumnSchema==========
        /*
                public string VAFMANDANT { get { if (dwMaster == null) return ""; return dwMaster["VAFMANDANT"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFMANDANT"] = value; OnPropertyChanged("VAFMANDANT", value); } } //lENGth 2
                public string VAFLIEFERSG { get { if (dwMaster == null) return ""; return dwMaster["VAFLIEFERSG"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFLIEFERSG"] = value; OnPropertyChanged("VAFLIEFERSG", value); } } //lENGth 1
                public string VAFPKUNDNR { get { if (dwMaster == null) return ""; return dwMaster["VAFPKUNDNR"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFPKUNDNR"] = value; OnPropertyChanged("VAFPKUNDNR", value); } } //lENGth 8
                public string VAFPWERK { get { if (dwMaster == null) return ""; return dwMaster["VAFPWERK"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFPWERK"] = value; OnPropertyChanged("VAFPWERK", value); } } //lENGth 3
                public string VAFPABT { get { if (dwMaster == null) return ""; return dwMaster["VAFPABT"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFPABT"] = value; OnPropertyChanged("VAFPABT", value); } } //lENGth 3
                public string VAFPLART { get { if (dwMaster == null) return ""; return dwMaster["VAFPLART"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFPLART"] = value; OnPropertyChanged("VAFPLART", value); } } //lENGth 20
                public double VAFSPERRDAT { get { if (dwMaster == null) return 0.0; return  Convert.ToDouble(dwMaster["VAFSPERRDAT"].ToString()); } set { if (dwMaster == null) return; dwMaster["VAFSPERRDAT"] = value; OnPropertyChanged("VAFSPERRDAT", value); } } //lENGth 0
                public string VAFKZZOLL2 { get { if (dwMaster == null) return ""; return dwMaster["VAFKZZOLL2"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFKZZOLL2"] = value; OnPropertyChanged("VAFKZZOLL2", value); } } //lENGth 1
                public string VAFMUFAEH { get { if (dwMaster == null) return ""; return dwMaster["VAFMUFAEH"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFMUFAEH"] = value; OnPropertyChanged("VAFMUFAEH", value); } } //lENGth 1
                public string VAFCOFAEH { get { if (dwMaster == null) return ""; return dwMaster["VAFCOFAEH"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFCOFAEH"] = value; OnPropertyChanged("VAFCOFAEH", value); } } //lENGth 1
                public double VAFMINPR1 { get { if (dwMaster == null) return 0.0; return  Convert.ToDouble(dwMaster["VAFMINPR1"].ToString()); } set { if (dwMaster == null) return; dwMaster["VAFMINPR1"] = value; OnPropertyChanged("VAFMINPR1", value); } } //lENGth 0
                public double VAFMINPR2 { get { if (dwMaster == null) return 0.0; return  Convert.ToDouble(dwMaster["VAFMINPR2"].ToString()); } set { if (dwMaster == null) return; dwMaster["VAFMINPR2"] = value; OnPropertyChanged("VAFMINPR2", value); } } //lENGth 0
                public string VAFABVK { get { if (dwMaster == null) return ""; return dwMaster["VAFABVK"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFABVK"] = value; OnPropertyChanged("VAFABVK", value); } } //lENGth 1
                public string VAFSFERTKZ { get { if (dwMaster == null) return ""; return dwMaster["VAFSFERTKZ"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFSFERTKZ"] = value; OnPropertyChanged("VAFSFERTKZ", value); } } //lENGth 1
                public string VAFEAN { get { if (dwMaster == null) return ""; return dwMaster["VAFEAN"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFEAN"] = value; OnPropertyChanged("VAFEAN", value); } } //lENGth 13
                public string VAFARTBEZ { get { if (dwMaster == null) return ""; return dwMaster["VAFARTBEZ"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFARTBEZ"] = value; OnPropertyChanged("VAFARTBEZ", value); } } //lENGth 10
                public string VAFZUSTAND { get { if (dwMaster == null) return ""; return dwMaster["VAFZUSTAND"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFZUSTAND"] = value; OnPropertyChanged("VAFZUSTAND", value); } } //lENGth 4
                public string VAFURCODE1 { get { if (dwMaster == null) return ""; return dwMaster["VAFURCODE1"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFURCODE1"] = value; OnPropertyChanged("VAFURCODE1", value); } } //lENGth 4
                public string VAFURCODE2 { get { if (dwMaster == null) return ""; return dwMaster["VAFURCODE2"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFURCODE2"] = value; OnPropertyChanged("VAFURCODE2", value); } } //lENGth 4
                public string VAFURCODE3 { get { if (dwMaster == null) return ""; return dwMaster["VAFURCODE3"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFURCODE3"] = value; OnPropertyChanged("VAFURCODE3", value); } } //lENGth 4
                public string VAFURCODE4 { get { if (dwMaster == null) return ""; return dwMaster["VAFURCODE4"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFURCODE4"] = value; OnPropertyChanged("VAFURCODE4", value); } } //lENGth 4
                public string VAFKZDUMCOL { get { if (dwMaster == null) return ""; return dwMaster["VAFKZDUMCOL"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFKZDUMCOL"] = value; OnPropertyChanged("VAFKZDUMCOL", value); } } //lENGth 1
                public string VAFLASCHE { get { if (dwMaster == null) return ""; return dwMaster["VAFLASCHE"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFLASCHE"] = value; OnPropertyChanged("VAFLASCHE", value); } } //lENGth 1
                public string VAFPVARKZ { get { if (dwMaster == null) return ""; return dwMaster["VAFPVARKZ"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFPVARKZ"] = value; OnPropertyChanged("VAFPVARKZ", value); } } //lENGth 1
                public string VAFSTANDARD { get { if (dwMaster == null) return ""; return dwMaster["VAFSTANDARD"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFSTANDARD"] = value; OnPropertyChanged("VAFSTANDARD", value); } } //lENGth 1
                public string VAFEANLASCHE { get { if (dwMaster == null) return ""; return dwMaster["VAFEANLASCHE"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFEANLASCHE"] = value; OnPropertyChanged("VAFEANLASCHE", value); } } //lENGth 13
                public string VAFFILLER { get { if (dwMaster == null) return ""; return dwMaster["VAFFILLER"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFFILLER"] = value; OnPropertyChanged("VAFFILLER", value); } } //lENGth 31
                public double VAFAENDZL { get { if (dwMaster == null) return 0.0; return  Convert.ToDouble(dwMaster["VAFAENDZL"].ToString()); } set { if (dwMaster == null) return; dwMaster["VAFAENDZL"] = value; OnPropertyChanged("VAFAENDZL", value); } } //lENGth 0
                public string VAFAENDBEN { get { if (dwMaster == null) return ""; return dwMaster["VAFAENDBEN"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFAENDBEN"] = value; OnPropertyChanged("VAFAENDBEN", value); } } //lENGth 8
                public string VAFNEUBEN { get { if (dwMaster == null) return ""; return dwMaster["VAFNEUBEN"].ToString(); } set { if (dwMaster == null) return; dwMaster["VAFNEUBEN"] = value; OnPropertyChanged("VAFNEUBEN", value); } } //lENGth 8
       */
        #endregion
    }

}
